package util;

import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;

import java.util.HashMap;

public class SmsUtil {

    public static String serverIp = "app.cloopen.com";
    //请求端口
    public static String serverPort = "8883";
    //主账号,登陆云通讯网站后,可在控制台首页看到开发者主账号ACCOUNT SID和主账号令牌AUTH TOKEN
    public static String accountSId = "8aaf070870e20ea1017152f5dd30378d";
    public static String accountToken = "36d58df9b8ef4049a93f9f081f298f71";
    //请使用管理控制台中已创建应用的APPID
    public static String appId = "8aaf070870e20ea1017152f5dd943794";


    public static boolean sendSms(String to, String templateId, String[] datas){
        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        sdk.init(serverIp, serverPort);
        sdk.setAccount(accountSId, accountToken);
        sdk.setAppId(appId);
        sdk.setBodyType(BodyType.Type_JSON);

        //请求发送短信
        HashMap<String, Object> result = sdk.sendTemplateSMS(to,templateId,datas);

        if("000000".equals(result.get("statusCode"))){
            System.out.println("短信发送成功");
            return true;
        }else{
            //异常返回输出错误码和错误信息
            System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
        }
        return false;
    }

}
